import { _decorator, Component, Node, EventTouch} from 'cc';
const { ccclass, property } = _decorator;
import { GameRoot } from './GameRoot';
import { TaKuSDK } from './TaKuSDK';
import { UserApi } from './api/user';
import { ENV } from './config/main';
@ccclass('Home')
export class Home extends Component {


    @property(Node)
    private ad_btn: Node = null;

    @property(Node)
    private start_btn: Node = null;

    start() {
        this.init();
    }

    init(){
        this.start_btn.on(Node.EventType.TOUCH_START, this.onStartGame, this);
        this.ad_btn.on(Node.EventType.TOUCH_START, this.onShowAd, this);
    }


    onStartGame(){
        this.node.parent.getComponent(GameRoot).onStartGame();
    }

    async onShowAd(){
        if(CC_DEBUG){
            UserApi.uploadAdRecord({
                appid: ENV.SDK.ANDROID.APP_ID,
                ad_id: "1234567890",
                remark: "测试"
            });
            return;
        }
        try{
            // 显示Rewarded广告
            TaKuSDK.getInstance().showRewardedVideoAd();
        }catch(e){
            console.log("showBannerAd error", e);
        }
    }

    

}


